<template>
  <div>
    <span>获取验证码（{{time}}s）</span>
  </div>
</template>

<script lang="ts" setup>
import { ref, watch } from "vue";
// 倒计时事件
let time = ref<number>(5);
let props = defineProps(["flag"]);
let $emit=defineEmits(['getFlag'])
watch(
  () => props.flag,
  () => {
    let timer = setInterval(() => {
      time.value--;
      if (time.value <= 0) {
        clearInterval(timer);
        $emit('getFlag',false)
      }
    }, 1000);
  },
  {
    immediate: true
  }
);
</script>

<style lang="scss" scoped>
</style>